package com.xmcc.controller;

import com.xmcc.common.ResultJson;
import com.xmcc.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("login")
public class LoginController {
    @Autowired
    private SysUserService sysUserService;

    @RequestMapping("login.json")
    public ResultJson login(HttpServletRequest request, String keyWord, String password){
        ResultJson login = sysUserService.login(keyWord,password);
        if (login.isResult()) {
            request.getSession().setAttribute("sysUser",login.getData());
        }
        //登录成功后应该回到刚才访问的位子
        return login;
    }

    @RequestMapping("logout.page")
    public String logout(HttpServletRequest request){
        request.getSession().invalidate();
        return "signin";
    }
}
